
        $(document).on('click','#btn_camera', function(){

            capturePhoto();
        });
        $(document).on('click','#btn_gellary', function(){

            openMedia_lib();
        });

        // Wait for Cordova to load
        //
        document.addEventListener("deviceready", onDeviceReady, false);
        // Cordova is ready
        //
        function onDeviceReady() {
        }

        function openMedia_lib(){
            // Retrieve image file location from specified source
            navigator.camera.getPicture(uploadPhoto,
            function(message) { alert('get picture failed'); },
            { quality: 50,
            destinationType: navigator.camera.DestinationType.FILE_URI,
            sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY }
            );
        }

        function uploadPhoto(imageURI) {
            var options = new FileUploadOptions();
            options.fileKey="fileImg";
            options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
            options.mimeType="image/jpeg";

            //var params = {};
            //params.value1 = "test";
            //params.value2 = "param";

            //options.params = params;
            $('#show_img').attr('src',imageURI);
            $('#avatar').val(imageURI);
            var ft = new FileTransfer();
            ft.upload(imageURI, encodeURI(_host_img + "/api/topic/testupload"), win, fail, options);
        }

        function win(r) {
            console.log("Code = " + r.responseCode);
            console.log("Response = " + r.response);
            $('#images').val();
            //alert(r.response);
            var class_css = 'thumb_border';
            $( ".gel_item" ).each(function() {
                //console.log($(this).attr('src'));
                class_css= '';
            });
            if(class_css != ''){
                $('#images').val(r.response);
            }
            var img = '<div class="col50 '+class_css+'">';
                img += '<img class="gel_item " style="float: left; width: 100%" src="'+_host_img+'/upload/image/'+r.response+'">';
                img += '  <div class="img_control" data-role="">';
                img += '    <button data_rel="'+r.response+'" class="img_set_thumnail ui-btn ui-icon-star ui-btn-icon-left ui-shadow ui-corner-all">Hình Đại Diện</button>';
                img += ' <button class="img_del ui-btn ui-icon-delete ui-btn-icon-left ui-shadow ui-corner-all">Xoá</button>';
                img += '<button class="img_close ui-btn ui-icon-power ui-btn-icon-left ui-shadow ui-corner-all">đóng</button>';
                img += '</div>';
                img += '    </div>';
                $('#img_append').append(img);
                //$('#images').val(_host_img+'/img/upload/test/'+r.response);
                console.log("Sent = " + r.bytesSent);
        }

        function fail(error) {
            alert("An error has occurred: Code = " + error.code);
            console.log("upload error source " + error.source);
            console.log("upload error target " + error.target);
        }
        //from camera
        // capture from camera
        function capturePhoto(){
            navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
            destinationType: Camera.DestinationType.FILE_URI });
        }

        function onSuccess(imageURI) {
            //alert(imageURI);
            //var image = document.getElementById('myImage');
            //image.src = imageURI;
            $('#show_img').attr('src',imageURI);
            uploadPhoto(imageURI);
        }

        function onFail(message) {
            alert('Failed because: ' + message);
        }



